Apache Wicket Interview Questions and Answers
Question: A sample web application using apache wicket.Answer:In Wicket, most stuffs are work by convention, you don’t need to configure it. In this case, WebApplication returns a “Hello.class” as the default page, when Wicket see this “Hello.class“, it know the mark up “html” page should be “Hello.html“, and it should be able to find at the same package directory. This is why Wicket need you to put both “html” and “java” class together. File : WelcomeApplication.java – The main application entrance. package com.withoutbook; import org.apache.wicket.Page; import org.apache.wicket.protocol.http.WebApplication; import com.withoutbook.hello.Hello; public class WelcomeApplication extends WebApplication { @Override public Class<? extends Page> getHomePage() { return Hello.class; //return default page } } File : Hello.java package com.withoutbook.hello; import org.apache.wicket.PageParameters; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.WebPage; public class Hello extends WebPage { private static final long serialVersionUID = 1L; public Hello(final PageParameters parameters) { add(new Label("message", "Hello World, Wicket")); } } File : Hello.html <html> <head> <title>Wicket Hello World</title> </head> <body> <h1> <span wicket:id="message">message will be replace later</span> </h1> </body> </html> To make Wicket works, you need to register Wicket filters in your web.xml file. <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>Wicket Web Application</display-name> <filter> <filter-name>wicket.wicketTest</filter-name> <filter-class>org.apache.wicket.protocol.http.WicketFilter</filter-class> <init-param> <param-name>applicationClassName</param-name> <param-value>com.withoutbook.WelcomeApplication</param-value> </init-param> </filter> <filter-mapping> <filter-name>wicket.wicketTest</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app> |
Is it helpful?
Yes
No
Most helpful rated by users:
- What is Wicket Framework?
- What are Wicket Models?
- What is Base class for HTML pages?
- What are the Ways to create a page in wicket?
- How to integrate apache-wicket with Spring?